package org.jeecg.modules.demo.hydrology.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.hydrology.dto.WzcddyDto;
import org.jeecg.modules.demo.hydrology.dto.WzcdssDto;
import org.jeecg.modules.demo.hydrology.entity.Wzcddy;
import org.jeecg.modules.demo.hydrology.entity.Wzcdss;
import org.jeecg.modules.demo.hydrology.mapper.WzcdssMapper;
import org.jeecg.modules.demo.hydrology.mapper.WzyjMapper;
import org.jeecg.modules.demo.hydrology.service.IWzcdssService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 微震实时
 * @Author: jeecg-boot
 * @Date:   2024-04-17
 * @Version: V1.0
 */
@Service
public class WzcdssServiceImpl extends ServiceImpl<WzcdssMapper, Wzcdss> implements IWzcdssService {
    @Autowired
    private WzcdssMapper wzcdssMapper;
    @Autowired
    private SysDepartMapper sysDepartMapper;
    /**
     * 微震实时-分页列表查询
     * @param page
     * @param queryWrapper
     * @return
     */
    @Override
    public IPage<WzcdssDto> getList(Page<Wzcdss> page, QueryWrapper<Wzcdss> queryWrapper) {
        Page<Wzcdss> wzcdssPage = wzcdssMapper.selectPage(page, queryWrapper);
        List<WzcdssDto> collect = wzcdssPage.getRecords().stream().map(wzcdss -> {
            WzcdssDto wzcdssDto = new WzcdssDto();
            BeanUtils.copyProperties(wzcdss, wzcdssDto);
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", wzcdss.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            if (sysDepart != null){
                wzcdssDto.setStationName(sysDepart.getDepartName());
            }
            return wzcdssDto;
        }).collect(Collectors.toList());
        IPage<WzcdssDto> wzcdssDtoIPage = new Page<>();
        wzcdssDtoIPage.setRecords(collect);
        wzcdssDtoIPage.setTotal(wzcdssPage.getTotal());
        wzcdssDtoIPage.setPages(page.getPages());
        wzcdssDtoIPage.setSize(page.getSize());
        return wzcdssDtoIPage;
    }
}
